<!DOCTYPE html>
<html lang="zh-Hans-CN">
<head>
    <meta charset="UTF-8">
    <title>学生列表案例</title>
    <meta name="viewport" content="width=device-width,initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <script src="../vue.js"></script>
</head>
<body>
<h2>【例17】学生列表案例</h2>
<hr>
<div id="app">
    <button @click="add">添加学生</button>
    <button @click="del">删除学生</button>
    <table border="1" width="50%" style="border-collapse: collapse">
        <tr>
            <th>班级</th>
            <th>姓名</th>
            <th>性别</th>
            <th>年龄</th>
        </tr>
        <tr align="center" v-for="s in stus">
            <td>{{s.grade}}</td>
            <td>{{s.姓名}}</td>
            <td>{{s.gender}}</td>
            <td>{{s.age}}</td>
        </tr>
    </table>
</div>

<script>
    let bh = 1;
    let vm = new Vue({
        el: '#app',
        data: {
            stus: [{grade: '1', 姓名: '陈老师', gender: '男', age: 21},
                {grade: '1', 姓名: '王铁锤', gender: '女', age: 22}]
        },
        methods: {
            add() {
                let student = {grade: '2', 姓名: '张三', gender: '男', age: 25};
                student.姓名 = "张三" + bh;
                bh++;
                this.stus.push(student)
            },
            del() {
                this.stus.pop()
            }
        }
    })
</script>
<hr>
<p><a href="index.html">返回章节目录</a>
    <script>document.write(document.lastModified); </script>
</p>
</body>
</html>
